import React, { useState } from 'react';
import ImgCrop from 'antd-img-crop';
import './postTopic.less';
import BasicLayout from "@/src/layouts";
import Nav from "@components/nav";
import updateUserInfo from "../../components/nav/updateUserInfo";
import { Button, Card, Divider, Input, Upload } from 'antd';
import API from '@common/api';
import MarkdownIt from 'markdown-it';
import MdEditor from 'react-markdown-editor-lite';
import 'react-markdown-editor-lite/lib/index.css';
import UploadPost from '@components/uploadPost/uploadPost';
const CutUpload = () => {
  const [fileList, setFileList] = useState([
    {
      uid: '-1',
      name: 'image.png',
      status: 'done',
      url: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
    },
  ]);

  const onChange = ({ fileList: newFileList }) => {
    setFileList(newFileList);
  };

  const onPreview = async file => {
    let src = file.url;
    if (!src) {
      src = await new Promise(resolve => {
        const reader = new FileReader();
        reader.readAsDataURL(file.originFileObj);
        reader.onload = () => resolve(reader.result);
      });
    }
    const image = new Image();
    image.src = src;
    const imgWindow = window.open(src);
    imgWindow.document.write(image.outerHTML);
  };
  return (
    <ImgCrop rotate>
      <Upload
        action="https://www.mocky.io/v2/5cc8019d300000980a055e76"
        listType="picture-card"
        fileList={fileList}
        onChange={onChange}
        onPreview={onPreview}
      >
        {fileList.length < 5 && '+ 添加图片'}
      </Upload>
    </ImgCrop>

  );
};
class PostTopic extends React.Component {
  handleEditorChange({ html, text }) {
    console.log('handleEditorChange', html, text);
  }

  // constructor() {
  //   super();
  //   updateUserInfo();
  //   if(localUserInfo['isLogin'])
  //     window.location.href = window.location.href;
  //
  // }

  render() {
    const mdParser = new MarkdownIt(/* Markdown-it options */);
    return (
      <div id="postTopicContainer">
        <BasicLayout header={<Nav />}>
        <Divider style={{marginTop:10, fontSize:30}}>发布</Divider>

        <UploadPost/>


        </BasicLayout>
      </div>

    )
  }
}

export default PostTopic;